//
//  TravelTourTwoCollectionViewCell.m
//  ToWhere
//
//  Created by dllo on 15/11/21.
//  Copyright © 2015年 www.TE.com. All rights reserved.
//

#import "TravelTourTwoCollectionViewCell.h"

#import <AVFoundation/AVFoundation.h>

@interface TravelTourTwoCollectionViewCell ()

@property (nonatomic, retain) AVPlayer *player;
@property (nonatomic, retain) UIButton *btn;
@property (nonatomic, retain) UIView *vw;
@end

@implementation TravelTourTwoCollectionViewCell
-(void)dealloc{
    [_model release];
    [_btn release];
    [_player release];
    [_vw release];
    [super dealloc];
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createView];
    }
    
    return self;
}

-(void)createView
{
  self.vw = [[UIView alloc]init];
    
    [self addSubview:self.vw];
    [_vw release];
    
    self.btn = [UIButton buttonWithType:UIButtonTypeCustom];
    //self.btn.backgroundColor = [UIColor redColor];
    [self.btn setImage:[UIImage imageNamed:@"bofang"] forState:UIControlStateNormal];
    [self addSubview:self.btn];
    
    
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.vw.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    self.player = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:self.model.video_url]];
    
    AVPlayerLayer *lay = [AVPlayerLayer playerLayerWithPlayer:_player];
    
    lay.frame = self.vw.frame;
    [self.vw.layer addSublayer:lay];
    
    
    self.btn.frame = CGRectMake(0, 0, 30 *kWidth, 30*kHeight);
    self.btn.center = self.vw.center;
    
}
-(void)setModel:(TravelTourSmallModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
  
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
